﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media.Animation;

namespace Extensions.Windows
{
    public static partial class FrameworkExtensions
    {
        private class FrameworkContentElementWrapper : IFrameworkElement
        {
            private readonly FrameworkContentElement element;

            internal FrameworkContentElementWrapper(FrameworkContentElement element)
            {
                this.element = element;
            }

            #region IInputElement

            public event MouseButtonEventHandler PreviewMouseLeftButtonDown
            {
                add { element.PreviewMouseLeftButtonDown += value; }
                remove { element.PreviewMouseLeftButtonDown -= value; }
            }
            public event MouseButtonEventHandler MouseLeftButtonDown
            {
                add { element.MouseLeftButtonDown += value; }
                remove { element.MouseLeftButtonDown -= value; }
            }
            public event MouseButtonEventHandler PreviewMouseLeftButtonUp
            {
                add { element.PreviewMouseLeftButtonUp += value; }
                remove { element.PreviewMouseLeftButtonUp -= value; }
            }
            public event MouseButtonEventHandler MouseLeftButtonUp
            {
                add { element.MouseLeftButtonUp += value; }
                remove { element.MouseLeftButtonUp -= value; }
            }
            public event MouseButtonEventHandler PreviewMouseRightButtonDown
            {
                add { element.PreviewMouseRightButtonDown += value; }
                remove { element.PreviewMouseRightButtonDown -= value; }
            }
            public event MouseButtonEventHandler MouseRightButtonDown
            {
                add { element.MouseRightButtonDown += value; }
                remove { element.MouseRightButtonDown -= value; }
            }
            public event MouseButtonEventHandler PreviewMouseRightButtonUp
            {
                add { element.PreviewMouseRightButtonUp += value; }
                remove { element.PreviewMouseRightButtonUp -= value; }
            }
            public event MouseButtonEventHandler MouseRightButtonUp
            {
                add { element.MouseRightButtonUp += value; }
                remove { element.MouseRightButtonUp -= value; }
            }
            public event MouseEventHandler PreviewMouseMove
            {
                add { element.PreviewMouseMove += value; }
                remove { element.PreviewMouseMove -= value; }
            }
            public event MouseEventHandler MouseMove
            {
                add { element.MouseMove += value; }
                remove { element.MouseMove -= value; }
            }
            public event MouseWheelEventHandler PreviewMouseWheel
            {
                add { element.PreviewMouseWheel += value; }
                remove { element.PreviewMouseWheel -= value; }
            }
            public event MouseWheelEventHandler MouseWheel
            {
                add { element.MouseWheel += value; }
                remove { element.MouseWheel -= value; }
            }
            public event MouseEventHandler MouseEnter
            {
                add { element.MouseEnter += value; }
                remove { element.MouseEnter -= value; }
            }
            public event MouseEventHandler MouseLeave
            {
                add { element.MouseLeave += value; }
                remove { element.MouseLeave -= value; }
            }
            public event MouseEventHandler GotMouseCapture
            {
                add { element.GotMouseCapture += value; }
                remove { element.GotMouseCapture -= value; }
            }
            public event MouseEventHandler LostMouseCapture
            {
                add { element.LostMouseCapture += value; }
                remove { element.LostMouseCapture -= value; }
            }
            public event StylusDownEventHandler PreviewStylusDown
            {
                add { element.PreviewStylusDown += value; }
                remove { element.PreviewStylusDown -= value; }
            }
            public event StylusDownEventHandler StylusDown
            {
                add { element.StylusDown += value; }
                remove { element.StylusDown -= value; }
            }
            public event StylusEventHandler PreviewStylusUp
            {
                add { element.PreviewStylusUp += value; }
                remove { element.PreviewStylusUp -= value; }
            }
            public event StylusEventHandler StylusUp
            {
                add { element.StylusUp += value; }
                remove { element.StylusUp -= value; }
            }
            public event StylusEventHandler PreviewStylusMove
            {
                add { element.PreviewStylusMove += value; }
                remove { element.PreviewStylusMove -= value; }
            }
            public event StylusEventHandler StylusMove
            {
                add { element.StylusMove += value; }
                remove { element.StylusMove -= value; }
            }
            public event StylusEventHandler PreviewStylusInAirMove
            {
                add { element.PreviewStylusInAirMove += value; }
                remove { element.PreviewStylusInAirMove -= value; }
            }
            public event StylusEventHandler StylusInAirMove
            {
                add { element.StylusInAirMove += value; }
                remove { element.StylusInAirMove -= value; }
            }
            public event StylusEventHandler StylusEnter
            {
                add { element.StylusEnter += value; }
                remove { element.StylusEnter -= value; }
            }
            public event StylusEventHandler StylusLeave
            {
                add { element.StylusLeave += value; }
                remove { element.StylusLeave -= value; }
            }
            public event StylusEventHandler PreviewStylusInRange
            {
                add { element.PreviewStylusInRange += value; }
                remove { element.PreviewStylusInRange -= value; }
            }
            public event StylusEventHandler StylusInRange
            {
                add { element.StylusInRange += value; }
                remove { element.StylusInRange -= value; }
            }
            public event StylusEventHandler PreviewStylusOutOfRange
            {
                add { element.PreviewStylusOutOfRange += value; }
                remove { element.PreviewStylusOutOfRange -= value; }
            }
            public event StylusEventHandler StylusOutOfRange
            {
                add { element.StylusOutOfRange += value; }
                remove { element.StylusOutOfRange -= value; }
            }
            public event StylusSystemGestureEventHandler PreviewStylusSystemGesture
            {
                add { element.PreviewStylusSystemGesture += value; }
                remove { element.PreviewStylusSystemGesture -= value; }
            }
            public event StylusSystemGestureEventHandler StylusSystemGesture
            {
                add { element.StylusSystemGesture += value; }
                remove { element.StylusSystemGesture -= value; }
            }
            public event StylusButtonEventHandler StylusButtonDown
            {
                add { element.StylusButtonDown += value; }
                remove { element.StylusButtonDown -= value; }
            }
            public event StylusButtonEventHandler PreviewStylusButtonDown
            {
                add { element.PreviewStylusButtonDown += value; }
                remove { element.PreviewStylusButtonDown -= value; }
            }
            public event StylusButtonEventHandler PreviewStylusButtonUp
            {
                add { element.PreviewStylusButtonUp += value; }
                remove { element.PreviewStylusButtonUp -= value; }
            }
            public event StylusButtonEventHandler StylusButtonUp
            {
                add { element.StylusButtonUp += value; }
                remove { element.StylusButtonUp -= value; }
            }
            public event StylusEventHandler GotStylusCapture
            {
                add { element.GotStylusCapture += value; }
                remove { element.GotStylusCapture -= value; }
            }
            public event StylusEventHandler LostStylusCapture
            {
                add { element.LostStylusCapture += value; }
                remove { element.LostStylusCapture -= value; }
            }
            public event KeyEventHandler PreviewKeyDown
            {
                add { element.PreviewKeyDown += value; }
                remove { element.PreviewKeyDown -= value; }
            }
            public event KeyEventHandler KeyDown
            {
                add { element.KeyDown += value; }
                remove { element.KeyDown -= value; }
            }
            public event KeyEventHandler PreviewKeyUp
            {
                add { element.PreviewKeyUp += value; }
                remove { element.PreviewKeyUp -= value; }
            }
            public event KeyEventHandler KeyUp
            {
                add { element.KeyUp += value; }
                remove { element.KeyUp -= value; }
            }
            public event KeyboardFocusChangedEventHandler PreviewGotKeyboardFocus
            {
                add { element.PreviewGotKeyboardFocus += value; }
                remove { element.PreviewGotKeyboardFocus -= value; }
            }
            public event KeyboardFocusChangedEventHandler GotKeyboardFocus
            {
                add { element.GotKeyboardFocus += value; }
                remove { element.GotKeyboardFocus -= value; }
            }
            public event KeyboardFocusChangedEventHandler PreviewLostKeyboardFocus
            {
                add { element.PreviewLostKeyboardFocus += value; }
                remove { element.PreviewLostKeyboardFocus -= value; }
            }
            public event KeyboardFocusChangedEventHandler LostKeyboardFocus
            {
                add { element.LostKeyboardFocus += value; }
                remove { element.LostKeyboardFocus -= value; }
            }
            public event TextCompositionEventHandler PreviewTextInput
            {
                add { element.PreviewTextInput += value; }
                remove { element.PreviewTextInput -= value; }
            }
            public event TextCompositionEventHandler TextInput
            {
                add { element.TextInput += value; }
                remove { element.TextInput -= value; }
            }

            public void RaiseEvent( RoutedEventArgs e )
            {
                element.RaiseEvent( e );
            }

            public void AddHandler( RoutedEvent routedEvent, Delegate handler )
            {
                element.AddHandler(routedEvent, handler);
            }

            public void RemoveHandler( RoutedEvent routedEvent, Delegate handler )
            {
                element.RemoveHandler( routedEvent, handler );
            }

            public bool CaptureMouse()
            {
                return element.CaptureMouse();
            }

            public void ReleaseMouseCapture()
            {
                element.ReleaseMouseCapture();
            }

            public bool CaptureStylus()
            {
                return element.CaptureStylus();
            }

            public void ReleaseStylusCapture()
            {
                element.ReleaseStylusCapture();
            }

            public bool Focus()
            {
                return element.Focus();
            }

            public bool IsMouseOver
            {
                get { return element.IsMouseOver; }
            }

            public bool IsMouseDirectlyOver
            {
                get { return element.IsMouseDirectlyOver; }
            }

            public bool IsMouseCaptured
            {
                get { return element.IsMouseCaptured; }
            }

            public bool IsStylusOver
            {
                get { return element.IsStylusOver; }
            }

            public bool IsStylusDirectlyOver
            {
                get { return element.IsStylusDirectlyOver; }
            }

            public bool IsStylusCaptured
            {
                get { return element.IsStylusCaptured; }
            }

            public bool IsKeyboardFocusWithin
            {
                get { return element.IsKeyboardFocusWithin; }
            }

            public bool IsKeyboardFocused
            {
                get { return element.IsKeyboardFocused; }
            }

            public bool IsEnabled
            {
                get { return element.IsEnabled; }
            }

            public bool Focusable
            {
                get { return element.Focusable; }
                set { element.Focusable = value; }
            }

            #endregion

            #region IFrameworkInputElement

            public string Name
            {
                get { return element.Name; }
                set { element.Name = value; }
            }

            #endregion

            #region ISupportInitialize

            public void BeginInit()
            {
                element.BeginInit();
            }

            public void EndInit()
            {
                element.EndInit();
            }

            #endregion

            #region IFrameworkElement

            public void BeginStoryboard( Storyboard storyboard )
            {
                element.BeginStoryboard( storyboard );
            }

            public void BeginStoryboard( Storyboard storyboard, HandoffBehavior handoffBehavior )
            {
                element.BeginStoryboard( storyboard, handoffBehavior );
            }

            public void BeginStoryboard( Storyboard storyboard, HandoffBehavior handoffBehavior, bool isControllable )
            {
                element.BeginStoryboard( storyboard, handoffBehavior, isControllable );
            }

            public void BringIntoView()
            {
                element.BringIntoView();
            }

            public object FindName( string name )
            {
                return element.FindName( name );
            }

            public object FindResource( object resourceKey )
            {
                return element.FindResource( resourceKey );
            }

            public BindingExpression GetBindingExpression( DependencyProperty dp )
            {
                return element.GetBindingExpression( dp );
            }

            public bool MoveFocus( TraversalRequest request )
            {
                return element.MoveFocus( request );
            }

            public DependencyObject PredictFocus( FocusNavigationDirection direction )
            {
                return element.PredictFocus( direction );
            }

            public void RegisterName( string name, object scopedElement )
            {
                element.RegisterName( name, scopedElement );
            }

            public BindingExpression SetBinding( DependencyProperty dp, string path )
            {
                return element.SetBinding( dp, path );
            }

            public BindingExpressionBase SetBinding( DependencyProperty dp, BindingBase binding )
            {
                return element.SetBinding( dp, binding );
            }

            public void SetResourceReference( DependencyProperty dp, object name )
            {
                element.SetResourceReference( dp, name );
            }

            public bool ShouldSerializeResources()
            {
                return element.ShouldSerializeResources();
            }

            public bool ShouldSerializeStyle()
            {
                return element.ShouldSerializeStyle();
            }

            public object TryFindResource( object resourceKey )
            {
                return element.TryFindResource( resourceKey );
            }

            public void UnregisterName( string name )
            {
                element.UnregisterName( name );
            }

            public ContextMenu ContextMenu
            {
                get { return element.ContextMenu; }
                set { element.ContextMenu = value; }
            }

            public Cursor Cursor
            {
                get { return element.Cursor; }
                set { element.Cursor = value; }
            }

            public object DataContext
            {
                get { return element.DataContext; }
                set { element.DataContext = value; }
            }

            public Style FocusVisualStyle
            {
                get { return element.FocusVisualStyle; }
                set { element.FocusVisualStyle = value; }
            }

            public bool ForceCursor
            {
                get { return element.ForceCursor; }
                set { element.ForceCursor = value; }
            }

            public InputScope InputScope
            {
                get { return element.InputScope; }
                set { element.InputScope = value; }
            }

            public bool IsInitialized
            {
                get { return element.IsInitialized; }
            }

            public bool IsLoaded
            {
                get { return element.IsLoaded; }
            }

            public XmlLanguage Language
            {
                get { return element.Language; }
                set { element.Language = value; }
            }

            public bool OverridesDefaultStyle
            {
                get { return element.OverridesDefaultStyle; }
                set { element.OverridesDefaultStyle = value; }
            }

            public DependencyObject Parent
            {
                get { return element.Parent; }
            }

            public ResourceDictionary Resources
            {
                get { return element.Resources; }
                set { element.Resources = value; }
            }

            public Style Style
            {
                get { return element.Style; }
                set { element.Style = value; }
            }

            public object Tag
            {
                get { return element.Tag; }
                set { element.Tag = value; }
            }

            public DependencyObject TemplatedParent
            {
                get { return element.TemplatedParent; }
            }

            public object ToolTip
            {
                get { return element.ToolTip; }
                set { element.ToolTip = value; }
            }

            public event ContextMenuEventHandler ContextMenuClosing
            {
                add { element.ContextMenuClosing += value; }
                remove { element.ContextMenuClosing -= value; }
            }

            public event ContextMenuEventHandler ContextMenuOpening
            {
                add { element.ContextMenuOpening += value; }
                remove { element.ContextMenuOpening -= value; }
            }

            public event DependencyPropertyChangedEventHandler DataContextChanged
            {
                add { element.DataContextChanged += value; }
                remove { element.DataContextChanged -= value; }
            }

            public event EventHandler Initialized
            {
                add { element.Initialized += value; }
                remove { element.Initialized -= value; }
            }

            public event RoutedEventHandler Loaded
            {
                add { element.Loaded += value; }
                remove { element.Loaded -= value; }
            }

            public event EventHandler<DataTransferEventArgs> SourceUpdated
            {
                add { element.SourceUpdated += value; }
                remove { element.SourceUpdated -= value; }
            }

            public event EventHandler<DataTransferEventArgs> TargetUpdated
            {
                add { element.TargetUpdated += value; }
                remove { element.TargetUpdated -= value; }
            }

            public event ToolTipEventHandler ToolTipClosing
            {
                add { element.ToolTipClosing += value; }
                remove { element.ToolTipClosing -= value; }
            }

            public event ToolTipEventHandler ToolTipOpening
            {
                add { element.ToolTipOpening += value; }
                remove { element.ToolTipOpening -= value; }
            }

            public event RoutedEventHandler Unloaded
            {
                add { element.Unloaded += value; }
                remove { element.Unloaded -= value; }
            }

            #endregion
        }
    }
}